/* Vecmath.

   Copyright (C) 2001, 2002, 2003 Stefan Maierhofer.

   Written by Stefan Maierhofer <sm@cg.tuwien.ac.at>

   This file is part of Vecmath.

   Vecmath is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   Vecmath is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Vecmath; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */

using System;
using NUnit.Framework;

namespace Vecmath
{

    /// <summary>
    /// Scale2F.
    /// </summary>
    public struct Scale2F
    {

        public static Scale2F Identity = new Scale2F(1,1);

        public Scale2F(float x, float y)
        {
            v = new Vec2F(x,y);
        }

        public Scale2F(Vec2F scale)
        {
            v = scale;
        }

        public float x { get { return v._x[0]; } }
        public float y { get { return v._x[1]; } }

        public Trafo2F ToTrafo2F()
        {
            return new Trafo2F(
                v._x[0], 0, 0,
                0, v._x[1], 0,
                0, 0, 1
                );
        }

        public static implicit operator Trafo2F(Scale2F s)
        {
            return s.ToTrafo2F();
        }

        public static Vec2F operator*(Vec2F v, Scale2F t)
        {
            return new Vec2F(
                v._x[0] * t.v._x[0],
                v._x[1] * t.v._x[1]
                );
        }

        public static Pnt2F operator*(Pnt2F p, Scale2F t)
        {
            return new Pnt2F(
                p._x[0] * t.v._x[0],
                p._x[1] * t.v._x[1]
                );
        }

        public static Box2F operator*(Box2F b, Scale2F t)
        {
            return new Box2F(b.Lower * t, b.Upper * t);
        }

        public static Trafo2F operator*(Shift2F a, Scale2F b)
        {
            return a.ToTrafo2F() * b.ToTrafo2F();
        }

        public static Trafo2F operator*(Rot2F a, Scale2F b)
        {
            return a.ToTrafo2F() * b.ToTrafo2F();
        }


        private Vec2F v;

    }

    [TestFixture]
    public class Scale2FTest
    {
        [Test]
        public void MulVec2F()
        {
            Vec2F v = new Vec2F(1,2);
            Scale2F t = new Scale2F(1,2);
            Assert.AreEqual(new Vec2F(1,4), v * t);
        }

        [Test]
        public void MulPnt2F()
        {
            Pnt2F p = new Pnt2F(1,2);
            Scale2F t = new Scale2F(1,2);
            Assert.AreEqual(new Pnt2F(1,4), p * t);
        }

        [Test]
        public void MulBox2F()
        {
            Box2F b = new Box2F(new Pnt2F(-1, -1), new Pnt2F(1,1));
            Scale2F t = new Scale2F(1,2);
            Assert.AreEqual(
                new Box2F(new Pnt2F(-1, -2), new Pnt2F(1,2)),
                b * t
                );
        }
    }

}
